<template>
	<view>
		<view class="edgeInsetTop"></view>
		<view class="cu-form-group">
			<view class="title">{{namets}}</view>
			<input type="text" placeholder="姓名" v-model="accountsData.name"></input>
		</view>
		<view class="cu-form-group" v-if="accountsData.type != 4">
			<view class="title">{{mobilets}}</view>
			<input type="number" placeholder="手机号码" maxlength="11" v-model="accountsData.mobile"></input>
		</view>
		
		<view class="cu-form-group" v-if="accountsData.type != 2">
			<view class="title">{{accountts}}</view>
			<input type="number" placeholder="帐号" maxlength="11" v-model="accountsData.account"></input>
		</view>
		
		<view class="cu-form-group margin-top-bj">
			<view class="title">设为默认</view>
			<switch @change="switchChange" :class="accountsData.default == 1?'checked':''" :checked="accountsData.default == 1"></switch>
		</view>
		
		<!-- 1.0.5升级 -->
		<!-- 1.0.6升级 -->
		<view class="padding-bj flex flex-direction margin-top">
			<button @tap="confirm" class="cu-btn wanl-bg-orange lg">完成</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				namets:'',
				mobilets:'',
				accountts:'',				
				accountsData: {
					type:'',
					name: '',
					mobile: '',
					type:'',
					account:'',
					default:1				
				},
				operate:'add'
			}
		},
		onLoad(option) {
			this.accountsData.type = option.type;

			let text = '新增';
			if (option.operate === 'edit'){
				text = '编辑';
			}
			let title = text+'手机号码 ';
			if (option.type == 2) {
				this.namets = '请填写姓名-方便下次查看';
				this.mobilets = '请填写要充值手机号码';				
			}
			if (option.type == 4) {
				this.namets = '请填写姓名-方便下次查看';
				this.accountts = '请填写要充值的文娱帐号';	
				title = text+'文娱帐号 ';			
			}
			
			if (option.type == 5) {
				this.namets = '请填写油卡绑定的真实姓名';
				this.mobilets = '请填写油卡绑定的手机号码'
				this.accountts = '请填写要充值的油卡帐号';
				title = text+'油卡信息';				
			}
			if (option.operate === 'edit') {			
				this.accountts = JSON.parse(option.data);		
			}
			this.$wanlshop.title(title);
		},
		onNavigationBarButtonTap() {
			this.confirm()
		},
		methods: {
			switchChange(e) {
				if (e.detail.value) {
					this.accountsData.default = 1;
				} else {
					this.accountsData.default = 0;
				}
			},
			//提交
			confirm() {
				let data = this.accountsData;
				if (!data.name) {
					this.$wanlshop.msg(this.namets);
					return;
				}
				if(this.accountsData.type != 4){
					if (!/^1[0-9]{10,10}$/.test(data.mobile)) { // 1.0.2升级
						this.$wanlshop.msg('请填写手机号码');
						return;
					}
				}
				if(this.accountsData.type != 2){
					if (!data.account) {
						this.$wanlshop.msg('请填写帐号');
						return;
					}
				}
				this.$wanlshop.prePage().refreshList1(data, this.operate);
				this.$wanlshop.msg(`地址${this.operate == 'edit' ? '修改': '添加'}成功`);
				this.$wanlshop.back(1);
			}
		}
	}
</script>

<style>
	.cu-form-group {
		padding: 0 25rpx;
	}
	/* 1.1.5升级 */
	.cu-form-group.area{
		position: relative;
	}
	.cu-form-group.area .click{
		position: absolute;
		z-index: 99;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
	}
	.cu-form-group .title {
		min-width: calc(4em + 15px);
		font-size: 26rpx;
	}

	.cu-form-group input,
	.cu-form-group textarea {
		font-size: 26rpx;
	}

	.cu-btn.lg {
		font-size: 32rpx;
		height: 86rpx;
	}

	.tipsScroll {
		width: 100%;
		height: 500rpx;
		padding: 0 50rpx;
	}

	.tipsScroll .item {
		margin: 25rpx 0;
	}

	.tipsScroll .item view {
		color: #B8B8B8;
		font-size: 22rpx;
	}

	.tipsScroll .item text {
		color: #333;
	}
</style>
